package sprites;

import controlador.GestorDeDibuix;
import java.awt.Point;
import java.util.Random;
import model.ModelJoc;

/**
 *
 * @author Carlos Moya Martinez
 */
public class NauEnemiga extends Player {

    private int sleeptime = 0;
    private int waitedtime = 0;
    private int sleeptime2 = 0;
    private int waitedtime2 = 0;
    Random desapareixer = new Random();

    public NauEnemiga(Point pantalla) {
        super((int) 3, false, pantalla);
        this.yMovementLimit = (((int) this.pantalla.getY() / 3) * 2) - (dimY / 2);
        this.x = this.randInRangeInc(0, (int) this.pantalla.getX());
        this.y = this.randInRangeInc(0, this.yMovementLimit);
        this.dimX = 96;
        this.dimY = 96;
        this.enemic = true;
        this.puntos = 3;
    }

    @Override
    public void shoot() {
        Missil missil = new Missil(this.x, this.y, this.pantalla);
        ModelJoc gm = ModelJoc.getInstancia();
        gm.afegirElement(missil);
    }

    @Override
    public void animar() {
        if (this.sleeptime < this.waitedtime) {
            this.sleeptime++;
        } else {
            this.x = this.randInRangeInc(0 + (dimX / 2), ((int) this.pantalla.getX() - (dimX / 2)));
            this.y = this.randInRangeInc(0 + (dimY / 2), this.yMovementLimit - (dimY / 2));
            this.sleeptime = 0;
            this.waitedtime = randInRangeInc(15, 30);
        }

        if (this.sleeptime2 < this.waitedtime2) {
            this.sleeptime2++;
        } else {
            this.shoot();
            this.sleeptime2 = 0;
            this.waitedtime2 = randInRangeInc(10, 90);
        }
    }

    private int randInRangeInc(int min, int max) {
        return min + (int) (Math.random() * (max - min));
    }

    @Override
    public void pintar() {
        GestorDeDibuix.getInstancia().pintar("SPACENEMESIS", getX() - (dimX / 2), getY() - (dimY / 2), dimX, dimY);
    }
}
